/**
 * Created by gongxun on 16/11/18.
 */

var KwxHelperLayer = KwxSecondBase.extend({
    ListView_rules : null,
    Button_tabs : null,
    ctor : function () {
        this._super();
        this.loadSecondCCS("res/ccs/KwxHelperLayer.json");
        this.setTitleText("res/ccs/hall_second/text/text_wanfajieshao.png");

        if (mo.gameHelper.projectCode != 2){
            this.loadUI();
            this.intoTab(0);
        }
    },

    loadUI : function(){
        this.ListView_rules = [];
        this.Button_tabs = [];
        for (var i = 0; i < 4; i++){
            var ListView_rule = mo.seekWidgetByName(this.ccsNode, "ListView_rule" + i);
            var Button_tab = mo.seekWidgetByName(this.ccsNode, "Button_tab" + i);

            this.ListView_rules.push(ListView_rule);
            this.Button_tabs.push(Button_tab);

            Button_tab.setTag(i);
            Button_tab.addTouchEventListener(function(sender, type){
                if (mo.gameHelper.getIsTouchEnd(type)){
                    this.intoTab(sender.getTag());
                }
            }, this);


            //修复剪切bug
            mo.gameHelper.setClippingLayout(ListView_rule);
        }


    },

    intoTab : function(index){
        var realRuleIndexs = [];
        if (mo.gameHelper.projectCode != 1){
            realRuleIndexs = [0, 1, 2, 3];
        }else{
            realRuleIndexs = [1, 3, 2, 0];
        }

        for (var i = 0; i < 4; i++){
            var isSelect = index == i;
            var realIndex = realRuleIndexs[i];

            this.ListView_rules[realIndex].setVisible(isSelect);
            var buttonStr = "res/ccs/hall_second/helper/tab_" + realIndex + "_" + (isSelect ? 0 : 1) + ".png";
            this.Button_tabs[i].loadTextureNormal(buttonStr);
        }
    }
});